<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path=request.getScheme()+"://"+request.getServerName()+":"+
	request.getServerPort()+request.getContextPath()+"/";
	pageContext.setAttribute("path", path);
%>
<!DOCTYPE html>
<html>
<head>
    <title>ONESTAR-在线医疗管理系统</title>
	<meta charset="UTF-8">
	<link rel="icon" href="static/img/me.jpg" type="image/x-icon" />
    <link rel="stylesheet" type="text/css" href="static/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="static/css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="static/css/style.css" />
    <link rel="stylesheet" type="text/css" href="static/css/regist-inner.css" />
    <!-- js -->
    <script type="text/javascript" src="static/js/jquery.js"></script>
    <script type="text/javascript" src="static/js/bootstrap.js"></script>
    <script type="text/javascript" src="static/js/ckform.js"></script>
    <script type="text/javascript" src="static/js/common.js"></script>
    <script type="text/javascript" src="static/js/jquery-3.4.1.js"></script>
    <script type="text/javascript" src="static/js/jquery.validate.js"></script>
    <script type="text/javascript" src="static/js/messages_zh.js"></script>

</head>
<body>
<div class="container">	
    <form class="form-signin" method="post" action="user" id = "form-signin">
    	<input type="hidden" name="method" value="regist">
        <h2 class="form-signin-heading" >管理员注册</h2>
        <p id="message" style="width: 400px;height: 30px;text-align: center;"></p>
                        姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：
		<input type="text" name="name" class="input-block-level" placeholder="账号">
		<br/>
                        密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：
        <input id="password" type="password" name="password" class="input-block-level" placeholder="密码">
        <br/>
                       确认密码：<input type="password" name="password2" class="input-block-level" placeholder="确认密码">
        <br/>
                        用&nbsp;&nbsp;户&nbsp;&nbsp;名：<input type="text" id="username" name="username" class="input-block-level" placeholder="用户名">
        <span id="username_msg"></span><br/>
                        邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱：<input type="text" id="email" name="email" class="input-block-level" placeholder="邮箱">
        <span id="email_msg"></span><br/>               
        <p style="text-align: center;">
        <input id=register type="button" value="注册" name="login" class="btn btn-large btn-info" style="width: 100px;"/>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input id="reset" type="reset" value="登录" name="login" class="btn btn-large btn-info" style="width: 100px;"/>
        </p>
    </form>
</div>

<script type="text/javascript">
/* 表单验证 */
$("#form-signin").validate({
	
	onfocusout: function(element) { $(element).valid(); },
	rules:{
		name:{
            required:true
        },
        password:{
            required:true
        },
        password2:{
        	required:true,
        	equalTo:"#password"
        } ,
        username:{
        	required:true,
        },
        email:{
        	required:true,
        	email:true
        }
    },
    messages:{
    	name:{
            required:"用户名不能为空"
        },
        password:{
            required: "密码不能为空"
        },
        password2:{
        	required: "确认密码必须和密码一样"
        } ,
        username:{
        	required: "用户昵称不能为空"
        },
        email:{
        	required: "邮箱格式不正确"
        }
    },
    errorElement: "em"
});

// 表单提交
$("#register").click(function(){
	var flag = $("#form-signin").valid();
	if(!flag){
		//没有通过验证
		alert("没有通过验证");
        return;
	}
	var data = $("#form-signin").serialize();
	$.ajax({
		url:"user/register",
		type:"post",
		data:data,
		dataType:"json",
		success:function(message){
			console.log(message);
			console.log(message.status_code);
			console.log(message.message);
			if(message.status_code == 200){
				$("#message").css("color","green");
				setTimeout(function(){

					location.href = "${path}";
				},1000) ;
				
			}else{
				$("#message").css("color","red");
			}
			$("#message").text(message.message);
		}
	});

});

// 返回登录页面
$("#reset").click(function () {
	window.location.href = "login.jsp";
}) 


</script>
</body>
</html>